﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MeTalker.BLL;
using MeTalker.Model;
public partial class Default_MembersForm : WebForm
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack) {
            string id = Request.QueryString["param"];
            BindData(id);
        }
    }

    void BindData(string id)
    {
        MembersMod members = MembersBLL.GetMembers(int.Parse(id));
       if (members != null)
       {
           txtAddDate.Text = members.AddDate.ToString("yyy-MM-dd HH:mm:ss");
           txtEmail.Text = members.Email;
           base.SetClientDate(txtExpireDate.ClientID, members.ExpireDate);
           txtHDID.Text = members.HDID;
           txtLatestOnline.Text = members.LatestOnline.ToString("yyy-MM-dd HH:mm:ss");
           txtMemo.Text = members.Memo;
           txtMobilePhone.Text = members.MobilePhone;
           txtQQ.Text = members.QQ;

           base.SetClientDate(txtRegistDate.ClientID, members.RegistDate);
           //txtRegistDate.Text = members.RegistDate.ToString("yyy-MM-dd HH:mm:ss");
           //txtSessionId.Text = members.SessionId;
           txtSoftID.Text = members.SoftID;
           txtSoftName.Text = members.SoftName;
           txtUserName.Text = members.UserName;
           ddlUserType.SelectedIndex = members.UserType.Equals("0") ? 0 : 1;
           ddlValid.SelectedIndex = members.IsValid == true ? 0 : 1;
           //ddlLoginFlag.SelectedIndex = members.LoginFlag == true ? 0 : 1;
           ddlLogonStatus.SelectedIndex = members.LoginFlag ? 1 : 0;
           Session["MembersMod"] = members;
       }
    }

    protected void btnAdd_Click(object sender, EventArgs e)
    {
       MembersMod members =Session["MembersMod"] as MembersMod;
       if (members != null)
       {
           members.ExpireDate = DateTime.Parse(txtExpireDate.Text);
           members.Memo=txtMemo.Text;
           string pass = txtPass.Text;
           if (!string.IsNullOrEmpty(pass))
               members.Password = GetMD5(pass);
           members.UserType = ddlUserType.SelectedIndex == 0 ? "0" : "1";
           members.LoginFlag = ddlUserType.SelectedIndex == 1 ? true : false;
           members.IsValid = ddlValid.SelectedIndex == 0 ? true : false;
           members.QQ = txtQQ.Text;
           members.MobilePhone = txtMobilePhone.Text;
           members.Email = txtEmail.Text;
           if (MembersBLL.Update(members) > 0)
           {
               Alert("数据修改成功", "closePanel", "RefreshData");
           }
           else {
               Alert("数据修改失败!");
           }
       }
    }
}